// pageDivination/pages/divinationResult/divinationResult.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        date: new Date().toDateString(),

        boardContentList: [
            {
                name: 'Love'
            },
            {
                name: 'CAUSE'
            },
            {
                name: 'FORTUNE'
            }
        ],

        boardAllList: [
            {name:'魔术师'},
            {name:'女祭司'},
            {name:'皇后'},
            {name:'皇帝'},
            {name:'教皇'},
            {name:'恋人'},
            {name:'战车'},
            {name:'力量'},
            {name:'隐士'},
            {name:'命运之轮'},
            {name:'正义'},
            {name:'倒吊者'},
            {name:'死神'},
            {name:'节制'},
            {name:'恶魔'},
            {name:'高塔'},
            {name:'星星'},
            {name:'月亮'},
            {name:'太阳'},
            {name:'审判'},
            {name:'世界'},
            {name:'愚人'}
        ]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
//获取三次不重复的随机数
    var index1 = getRandomInRange(0,9,[]);
    var index2 = getRandomInRange(0,9,[index1]);
    var index3 = getRandomInRange(0,9,[index1,index2]);
    this.data.boardContentList[0] = this.data.boardAllList[index1];
    this.data.boardContentList[1] = this.data.boardAllList[index2];
    this.data.boardContentList[2] = this.data.boardAllList[index3];
    //设置参数
    this.setData({
        boardContentList:this.data.boardContentList
    });
    console.log(" index1 : "+index1 +" index2 : "+index2 +" index3 : "+index3);
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    },

    gotoDivinationDetail() {
        console.log('gotoDivinationDetail')
        wx.navigateTo({
            url: '/pageDivination/pages/divinationDetail/divinationDetail',
          })
    }
})

/**
 * 获取不重复的随机数
 * @param {*} min 最小随机数
 * @param {*} max 最大随机数
 * @param {*} arr 以获取随机数数组
 */
function getRandomInRange(min, max,arr) {
    var random = Math.floor(Math.random() * (max - min + 1)) + min;
    
    //当以获取随机数等于可获取的最大随机数则直接返回
    if(arr.length == ((max-min)+1)){
        return random;
    }
    while(arr.indexOf(random) != -1){
        random = Math.floor(Math.random() * (max - min + 1)) + min;
    }
    return random;
}